package com.cvs.service.impl;

import com.cvs.bean.Sign;
import com.cvs.dao.SignMapper;
import com.cvs.service.SignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service("signService")
public class SignServiceImpl implements SignService {
  @Autowired
    private  SignMapper signMapper;
    @Override
    public int addSign(Sign sign) {
      if (signMapper.getSign(sign.getUid()) > 0) {
        return (-1);
      } else {
        return signMapper.addSign(sign);
      }

    }

  @Override
  public List<Sign> signDay(Integer uid) {
    return signMapper.signDay(uid);
  }

  @Override
  public int signCount(Integer uid) {
      List<Sign> signs= signMapper.signDay(uid);
    int sday=0;
    int count=0;
    for (Sign sign: signs) {
      //1.当前统计一个月内容累计签到次数
      //2。当天日期数
      //判断小于等于当天
      if(sday==0){
      sday=sign.getDay();
      count=1;
      }else {
        if(sday+1==sign.getDay()){
          sday=sign.getDay();
       count=count+1;
        }else {
          sday=sign.getDay();
          count=1;
        }
      }

    }
    return count;
  }
}
